package com.neuedu.boot.controller;

import com.neuedu.boot.po.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 金山
 * 项目：boot-learn
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/2014:25
 */
@RestController
@RequestMapping("/user")
public class UserController {


    /**
     // * http://127.0.0.1:8080/user/get/1
     * @param id
     * @return
     */
    @RequestMapping("/get/{id}")
    public User getUserById(@PathVariable  int id){

        //模拟从数据库
        User user = new User();
        user.setId(1);
        user.setUsername("admin");
        user.setBirthday(new Date());
        user.setTestDate(new Date());
        return user;

    }


    @RequestMapping("/list")
    public List<User> list(){

       List userList = new ArrayList();
        for (int i = 1; i <= 10; i++) {
            //模拟从数据库
            User user = new User();
            user.setId(i);
            user.setUsername("admin"+i);
            userList.add(user);
        }

        return userList;

    }




    @RequestMapping("/save")
    public String save(User user){

        // 使用打印  模拟存储数据库
        System.out.println(user);

        return "保存成功";

    }



}
